/**
 * 
 */
package br.srv.full.virtual.faces.beanutils;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

import br.srv.full.virtual.entities.ids.StateId;

/**
 * @author Delfino
 * 
 */
public class StatelIdConverter extends BaseIdConverter {

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.faces.convert.Converter#getAsObject(javax.faces.context.FacesContext,
	 *      javax.faces.component.UIComponent, java.lang.String)
	 */
	@Override
	public Object getAsObject(FacesContext p_context, UIComponent p_component, String p_value) {
		log.info(p_value);
		log.info(p_component);
		log.info(p_context);
		p_value = p_value.trim();
		int l_index = p_value.indexOf(' ');
		if (l_index == -1)
			return new StateId(p_value);
		else
			return new StateId(p_value.substring(0, l_index).trim(), p_value.substring(l_index).trim());
	}

	
	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.faces.convert.Converter#getAsString(javax.faces.context.FacesContext,
	 *      javax.faces.component.UIComponent, java.lang.Object)
	 */
	@Override
	public String getAsString(FacesContext p_context, UIComponent p_component, Object p_value) {
		log.info(p_value);
		log.info(p_component);
		log.info(p_context);
		return ((StateId)p_value).getNumber();
	}

}
